package com.example.redis.myJredis;

import redis.clients.jedis.Jedis;

public class RedisExample {
    public static void main(String[] args) {
        Jedis redis = new  Jedis("localhost",6379);
//      SimpleExample(redis);

//      ListExample(redis,20000);

        PublishExample(redis,20000);
    }
    //简单添加信息
    public static void SimpleExample(Jedis redis){
        redis.set("key1", "I am value 1");
        String ss = redis.get("key1");
        System.out.println(ss);
    }
    //队列添加信息
    public static void ListExample(Jedis redis,int number){
        String messageStr = "";
        int count = 0;
        while(count++ < number){
            messageStr =  "this is "+count+" message!";
            redis.rpush("logstash-test-list",messageStr);
            System.out.println(messageStr);
        }
    }
    //发布订阅
    public static void PublishExample(Jedis redis,int number){
        String messageStr = "";
        int count = 0;
        while(count++ < number){
            messageStr =  "this is "+count+" message!";
            redis.publish("logstash-test-list",messageStr);
            System.out.println(messageStr);
        }
    }
}